package cn.com.callback

import cn.com.elite.EliteBean
import cn.com.elite.Util
import cn.com.kh.KHDBConfig
import cn.com.kh.KHUtil
import com.alibaba.fastjson.JSONObject
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/**
 *
 * @Title: apiWorkNum
 * @Description:获取工单待处理数量
 * @author: Rick* @date 2022-04-27 13:42:22
 *
 */

public class apiWorkNum implements ServiceBackInvoke {
    private static final Log log = LogFactory.getLog(apiWorkNum.class);

    public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response) {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json");
        net.sf.json.JSONObject result = new net.sf.json.JSONObject();
        def smap,smap1;
        try {
            def userid = Util.filterForObject(request.getParameter("loginName")); //客户ID
            log.debug("传参:" + userid);
            //传参处理

            //列表接口调用
            if (userid.equals("")) {
                result.put("code", "-1");
                result.put("msg", "未传递参数！");
                return result
            }
            smap = eliteBean.chaxun_sql("select sr.ROLEGROUP_ID,sr.STAFF_ID from staff s  left join staffrolegroup sr  on s.staff_id=sr.staff_id where loginname='"+userid+"' limit 1", "dataSource");
                if(smap.size()==0){
                    result.put("code", "-2");
                    result.put("msg", "当前账号数据未查到，请核实！");
                    return result;
                }else{
                    smap1 = eliteBean.chaxun_sql("select  count(distinct o.objective_guid) as num from objective o left join  elitetask t  on t.objective_guid=o.objective_guid WHERE 1=1  and o.objectivestatus='OPEN'  And t.HandleBy_ID='"+smap[0].getAt("STAFF_ID")+"'","dataSource");

                    result.put("code", "200");
                    result.put("num", smap1[0].getAt("num"));
                    result.put("msg", "调用待处理数量数据成功！");
                    return result;
                }

        } catch (Exception e) {
            log.error("errormsg:", e)
            result.put("code", "-1");
            result.put("msg", "调用失败！");
            return result;
        }
    }

}
